package org.brain.bean;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import org.brain.dbo.DBOperate;
import org.brain.pojos.Commentinfo;
import org.brain.pojos.Document;
import org.brain.pojos.Messagetable;
import org.brain.pojos.User;
import org.brain.tool.ToolBean;

@ManagedBean(name="messagemanager")
@SessionScoped
public class MessageManager {
	private Integer messageid;
	private String messgecontent;
	private Date messagetime;
	private String messageuser;
	private String messagefrom;
	private String messagetitle;
	private Messagetable messagtable= new Messagetable();
	private Messagetable messagtable1= new Messagetable();
	int row = 0;
	
	public void initaddMessage(){
		User user;
		user = ToolBean.getUserSession();
		messagefrom=user.getUsername();
		boolean flag=false;
		messagtable.setMessagecontent(messgecontent);
		messagtable.setMessagefrom(messagefrom);
		messagtable.setMessagetitle(messagetitle);
		messagtable.setMessagetype(1);
		messageuser=ToolBean.getRequestParameter("messageuser");
		messagtable.setMessageuser(messageuser);
		messagetime=new Date();
		messagtable.setMessagetime(messagetime);
		flag = DBOperate.save(messagtable);
		messagtable1.setMessagecontent(messgecontent);
		messagtable1.setMessagefrom(messageuser);
		messagtable1.setMessagetitle(messagetitle);
		messagtable1.setMessagetype(3);
		messagtable1.setMessageuser(messagefrom);
		messagtable1.setMessagetime(messagetime);
        flag=DBOperate.save(messagtable1);
	}
	public void initsavMessage(){
		User user;
		user = ToolBean.getUserSession();
		messagefrom=user.getUsername();
		boolean flag=false;
		messagtable.setMessagecontent(messgecontent);
		messagtable.setMessagefrom(messageuser);
		messagtable.setMessagetitle(messagetitle);
		messagtable.setMessagetype(4);
		messagtable.setMessageuser(messagefrom);
		messagetime=new Date();
		messagtable.setMessagetime(messagetime);
		flag = DBOperate.save(messagtable);
	}
	public int getRow() {
		return row;
	}
	public void setRow(int row) {
		this.row = row;
	}
	public void setMessageid(Integer messageid) {
		this.messageid = messageid;
	}
	public Integer getMessageid() {
		return messageid;
	}
	public String getMessgecontent() {
		return messgecontent;
	}
	public void setMessgecontent(String messgecontent) {
		this.messgecontent = messgecontent;
	}
	public Date getMessagetime() {
		return messagetime;
	}
	public void setMessagetime(Date messagetime) {
		this.messagetime = messagetime;
	}
	public String getMessageuser() {
		messageuser=ToolBean.getRequestParameter("messageuser");
		return messageuser;
	}
	public void setMessageuser(String messageuser) {
		this.messageuser = messageuser;
	}
	public String getMessagefrom() {
		return messagefrom;
	}
	public void setMessagefrom(String messagefrom) {
		this.messagefrom = messagefrom;
	}
	public String getMessagetitle() {
		return messagetitle;
	}
	public void setMessagetitle(String messagetitle) {
		this.messagetitle = messagetitle;
	}
	public Messagetable getMessagtable() {
		return messagtable;
	}
	public void setMessagtable(Messagetable messagtable) {
		this.messagtable = messagtable;
	}
	public void setMessagtable1(Messagetable messagtable1) {
		this.messagtable1 = messagtable1;
	}
	public Messagetable getMessagtable1() {
		return messagtable1;
	}

}
	


